//
//  WarehouseJudgeModel.swift
//  SWHProject
//
//  Created by 孙先华 on 2020/6/16.
//  Copyright © 2020 孙先华. All rights reserved.
//

import Foundation
import HandyJSON

class ArticleListModel: HandyJSON {
    required init() {
    }
    var status :String?
    var totalResults :Int = 0
    var articles :[ArticleItemModel] = Array()
    
    func handleData(){
        for item in articles {
            item.handleData()
        }
    }
    
}

class ArticleItemModel: HandyJSON {
    required init() {
    }
    
    var source :SourceModel!
    var author :String = ""
    var title  :String = ""
    var description :String = ""
    var url :String = ""
    var urlToImage :String = ""
    var publishedAt :String = ""
    var content :String = ""
    
    //增加字段
    var titleHeight :CGFloat = 0.0
    var contentHeight :CGFloat = 0.0
    var sumHeight :CGFloat = 0.0
    
    
    func handleData(){
        
        titleHeight = self.title.getLabHeigh(font: UIFont.boldSystemFont(ofSize: 20.0), width: ScreenWidth-50.0).height + 10.0
        contentHeight = self.content.getLabHeigh(font: UIFont.systemFont(ofSize: 16.0), width: ScreenWidth-50.0).height + 10.0
        
        let minHeight :CGFloat = 40.0
        titleHeight = titleHeight < minHeight ? minHeight : titleHeight
        contentHeight = contentHeight < minHeight ? minHeight: contentHeight
        
        let height = titleHeight + contentHeight + 50.0
        sumHeight = urlToImage.length == 0 ? height : (height + 250.0)
        
        sumHeight += 30.0
        
    }
    
    
}

class SourceModel: HandyJSON {
    
    required init() {
    }
    var id :String = ""
    var name :String = ""
}
